﻿using System.Web.Mvc;
using System.Web.Routing;
using SlamCms.Web;
using SlamCmsDemo.Data;

namespace SlamCmsDemo.Web.Core.Bootstrappers
{
	public class B01MvcAndRouting : Bootstrapper
	{
		public override void PostApplicationStart(PostApplicationStartContext context)
		{
			RegisterRoutes(RouteTable.Routes);
		}

		protected void RegisterRoutes(RouteCollection routes)
		{
			routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

			routes.MapSharePointImages("ContentImages", "Content Images");
			routes.MapRoute("SharepointDownload", "download-file/{contentItemId}/{slug}", new { controller = "ContentItem", action = "Download", slug = UrlParameter.Optional });

			routes.MapRoute("ContentItemDetailsLink", "link/{contentItemId}", new { controller = "ContentItem", action = "ContentItemDetailsLink" });
			routes.MapRoute("ContentItemDetails", "{contentType}/{contentItemId}/{slug}")
				  .AddDefaults(new { controller = "ContentItem", action = "Details", slug = UrlParameter.Optional })
				  .AddConstraint("contentType", ListConstraint.Create("Article", "Download", "Event", "Faq")); // TODO use registered content types

			routes.MapTagBrowser(Constants.TagBrowsers.KnowledgeCenter);

			routes.MapRoute("CalendarAdd", "Calendar/Add/{eventId}", new { controller = "Calendar", action = "Add" });
			routes.MapTagBrowser(Constants.TagBrowsers.CalendarList, "Calendar/List").AddDefaults(new { controller = "Calendar", action = "List" });

			routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional });
		}
	}
}